﻿Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.SqlClient
Imports CodeMatrix.Context

' Created by Boonyarit Yingvoragan
' Created date 29/10/2553
Public Class StpAuthenDepartment

    Public Shared Function Delete(ByVal tbl As String, ByVal pid As String, ByVal cid As String) As Int32

        Dim affectedRecord = -1
        Using c As New SqlConnection(CodeMatrix.Utilities.CodeHelper.ConnectionString)

            Dim cmd As New SqlCommand()
            cmd.CommandText = "EXEC  [dbo].[USP_GenericDelete] @tbl,@pid,@cid;"
            cmd.Connection = c

            cmd.Parameters.Add(New SqlParameter("@tbl", tbl))
            cmd.Parameters.Add(New SqlParameter("@pid", pid))
            cmd.Parameters.Add(New SqlParameter("@cid", cid))

            If c.State <> ConnectionState.Open Then
                c.Open()
            End If
            affectedRecord = cmd.ExecuteNonQuery()

            ' =========================================================
            ' Log command
            ' =========================================================
            Dim e As New OrderedDictionary()
            e.Add(pid, cid)
            GenericHelper.GenerateScript(GenerateScriptLogType.Delete, LogMenuType.stp_auth_department, e)
        End Using

        Return affectedRecord

    End Function

    Public Shared Function GetData(ByVal department_code As Int32, ByVal department_status As Int32, ByVal staff_code As Int32) As DataTable

        ' =========================================================================
        ' Get table
        ' =========================================================================
        Dim tbl = CodeMatrix.Utilities.CodeHelper.GetDataTable( _
            "exec USP_Filter_stp_auth_department @staff_code, @department_code , @department_status", _
             New SqlParameter("@staff_code", staff_code), _
             New SqlParameter("@department_code", department_code), _
             New SqlParameter("@department_status", department_status) _
            )

        tbl = StpDepartment.ArrangeData(tbl)

        Return tbl

    End Function

End Class
